package handler

import (
	"ecommerce-customer-support-chat/api/request"
	"ecommerce-customer-support-chat/global"
	"ecommerce-customer-support-chat/internal/dao"
	"ecommerce-customer-support-chat/internal/model"
	"github.com/gin-gonic/gin"
	"net/http"
)

func QueryComment(c *gin.Context) {
	var req request.QueryCommentReq
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 500,
			"msg":  "查询失败",
			"data": err.Error(),
		})
		return
	}
	var comment model.Comments
	dao.GetOneByFields(&model.Comments{
		Id: req.Id,
	}, &comment)
	if comment.Id == 0 {
		c.JSON(http.StatusOK, gin.H{
			"code": 10001,
			"msg":  "消息不存在",
			"data": nil,
		})
		return
	}
	err := global.DB.Where("created_at or chat").Limit(1).Find(&comment).Error
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 10002,
			"msg":  "查询失败",
			"data": nil,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "查询成功",
		"data": comment,
	})

}
